<template>
    <div class="background">
        <div class="top">
            <div class="time-display">
                <span class="date-text">{{ currentDate }}</span>
                <span class="time-text">{{ currentTime }}</span>
            </div>
            <div class="top-title">
                证券分时数据监控系统
            </div>
            <div class="news-button" @click="toggleNews" v-if="showNewsButton">
                <!-- <img :src="getNewsIcon(this.showNews)" alt="news-icon" /> -->
                <img v-if="showNews" src="../assets/closed.svg" alt="news-icon" />
                <img v-else src="../assets/bigbell.svg" alt="news-icon" />
                
                </div>
                <div class="Totop" @click="Totop" v-if="topbtn">
                    <img  src="../assets/top.svg" alt="news-icon" />
                </div>
        </div>
        <div class="flex-container">
            <div class="flex-column">
                <div class="flex-row">
                    <div class="flex-item" style="width: 50%;  margin-right: 15px;">
                        <div class="title-wrapper">
                            <h2 class="title">中国指数</h2>
                        </div>
                        <div class="flex-item-content">
                            <ChinaIndex></ChinaIndex> 
                        </div>
                        <div class="flex-item-footer">
<!-- 用于生成左下和右下的小尖角 -->
                        </div>
                    </div>
                    <div class="flex-item" style="width: 50%; ">
                        <div class="title-wrapper">
                            <h2 class="title">新股上市日历</h2>
                        </div>
                        <div class="flex-item-content">
                            <Calender></Calender> 
                        </div>
                        <div class="flex-item-footer">

                        </div>
                    </div>
                </div>
                <div class="flex-row" style="margin-top: 15px;">
                    <div class="flex-item" style="width: 60%;  margin-right: 15px;">
                        <div class="title-wrapper">
                            <h2 class="title">港股通资金流</h2>
                        </div>
                        <div class="flex-item-content">
                            <HKFlow></HKFlow> 
                        </div>
                        <div class="flex-item-footer">

                        </div>
                    </div>
                    <div class="flex-item" style="width: 40%; ">
                        <div class="title-wrapper">
                            <h2 class="title">板块资金流</h2>
                        </div>
                        <div class="flex-item-content">
                            <CapitalFlow></CapitalFlow> 
                        </div>
                        <div class="flex-item-footer">

                        </div>
                    </div>
                </div>
            </div>
            <div class="flex-item news-container" :class="{ 'show': showNews }" style="width: 25%; height: 100%; margin-left: 25px;">
                <div class="title-wrapper">
                    <h2 class="title">证券快讯</h2>
                </div>
                <div class="flex-item-content">
                            <News></News> 
                        </div>
                <div class="flex-item-footer">

                </div>
            </div>
        </div>
    </div>
</template>
<script>
import ChinaIndex  from './ChinaIndex.vue'
import Calender  from './Calender.vue'
import CapitalFlow  from './CapitalFlow.vue'
import HKFlow  from './HKFlow.vue'
import News  from './News.vue'

export default {
    components:{ChinaIndex,Calender,CapitalFlow,HKFlow,News},
    data() {
        return {
            currentTime: '',
            currentDate: '',
            showNews: false,
      showNewsButton: false,
      topbtn: false,

        }
    },
    mounted() {
        this.updateDateTime();
        this.interval = setInterval(this.updateDateTime, 1000);
    },
    created() {
    this.checkMediaQuery();
    window.addEventListener('resize', this.checkMediaQuery);
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.checkMediaQuery);
  },
    beforeUnmount() {
        clearInterval(this.interval);
    },
    methods: {
        updateDateTime() {
            const now = new Date();
            this.currentTime = this.formatTime(now);
            this.currentDate = this.formatDate(now);
        },
        formatTime(date) {
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${hours}:${minutes}:${seconds}`;
        },
        formatDate(date) {
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            return `${month}-${day}`;
        },
        checkMediaQuery() {
      if (window.matchMedia('(max-width: 768px)').matches) {
        this.showNewsButton = true;
        this.showNews = false;
        this.topbtn = true;
      } else {
        this.showNewsButton = false;
        this.showNews = true;
        this.topbtn = false;
      }
    },
    toggleNews() {
      this.showNews = !this.showNews;
    },
    Totop(){
        const background = document.querySelector('.background');
        background.scrollTop = 0;
    },
    }
}
</script>

<style scoped>
.background {
    /* 使用fix会导致无法滚动 */
    position: fixed; 
    width: 100%;
    height: 100%;
    background: url('../assets/images/背景板.png');
    /* z-index: -1; */
    overflow:scroll;
}

.top {
    display: flex;
    width: 100%;
    height: 50px;
}

.time-display {
    position: fixed;
    margin-left: 20px;
    padding-top: 30px;
}

.top-title {
    margin: 0 auto;
    text-align: center;
    font-size: 30px;
    font-weight: bold;
    background-image: linear-gradient(to bottom, white, rgb(0, 102, 255));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
@font-face {
    font-family: 'Digital-7 Mono';
    src: url('../assets/Digital-7.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* LED字体 */
.date-text,
.time-text {
    font-family: 'Digital-7 Mono', monospace;
    font-size: 36px;
    color: white;
    /* text-shadow: 0 0 10px rgba(2, 166, 181, 0.8);s */
    margin-left: 15px;
}

.date-text {
    margin-bottom: 10px;
}

.flex-container {
    width: 96%;
    height: 90%;
    margin: 0 auto;
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    
}

.flex-column {
    width: 75%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.flex-row {
    display: flex;
    height: 50%;
    flex-direction: row;
    justify-content: space-between;
}

.flex-item {
    position: relative;
    background-color: #05174d;
    border: 2px solid rgba(25, 186, 139, 0.17);
    ;
    padding: 1px;
    text-align: center;
    box-sizing: border-box;
    /* overflow:hidden; 导致伪类消失的罪魁祸首*/ 
}

.flex-item::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 10px;
    height: 10px;
    border-top: 2px solid #02a6b5;
    border-left: 2px solid #02a6b5;
    transform: translate(-50%, -50%);
    /* 这行代码可以将小方块移动到左上角 ，加小尖角*/
}

.flex-item::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -3px;
    width: 10px;
    height: 10px;
    border-top: 2px solid #02a6b5;
    border-right: 2px solid #02a6b5;
    /* 右上尖角 */
}

.flex-item-footer {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
}

.flex-item-footer::before {
    position: absolute;
    bottom: -2px;
    left: -2px;
    content: "";
    width: 10px;
    height: 10px;
    border-bottom: 2px solid #02a6b5;
    border-left: 2px solid #02a6b5;
}

.flex-item-footer::after {
    position: absolute;
    bottom: -2px;
    right: -2px;
    content: "";
    width: 10px;
    height: 10px;
    border-bottom: 2px solid #02a6b5;
    border-right: 2px solid #02a6b5;
}

.title-wrapper {
    background-image: linear-gradient(to right, #05174d, #043b9a, #05174d);
    padding: 10px 10px;
    margin-bottom: 8px;
    border-radius: 5px;
}

.title {
    text-align: center;
    color: white;
    font-size: 24px;
    font-weight: bold;
}
@media (max-width: 768px) {
    
  .flex-container {
    flex-direction: column;
    height: auto;
  }

  .flex-column {
    width: 100%;
    height: auto;
  }

  .flex-row {
    flex-direction: column;
    height: auto;
  }

  .flex-item {
    width: 100% !important;
    height: 450px;
    margin-right: 0 !important;
    margin-bottom: 15px;
  }
  .time-display{
    position: absolute;
    margin-left: 20px;
    padding-top: 40px;

  }
  .date-text,
.time-text {
    font-family: 'Digital-7 Mono', monospace;
    font-size: 25px;
    color: white;
    /* text-shadow: 0 0 10px rgba(2, 166, 181, 0.8);s */
    margin-left: 15px;
}
  .news-container {
    display: none;
  }

  .news-container.show {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    width: 60%;
    height: 100%;
    background-color: #05174d;
    border: 2px solid rgba(25, 186, 139, 0.17);
    box-sizing: border-box;
    z-index: 1;
    animation: slideIn 0.3s ease-in-out;
  }

  .news-button {
  position: fixed;
  top: 15px;
  right: 5px;
  background-color: rgba(86, 95, 122, 0.4);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid rgba(25, 186, 139, 0.17);
  cursor: pointer;
  z-index: 2;
}

.Totop {
  position: fixed;
  bottom: 60px;
  right: 15px;
  background-color: rgba(5, 23, 77, 0.7);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid rgba(25, 186, 139, 0.17);
  cursor: pointer;
  z-index: 1;
}
  @keyframes slideIn {
    0% {
      transform: translateX(100%);
    }
    100% {
      transform: translateX(0);
    }
  }
}
</style>